/**
 * 
 */
package adnotatio.renderer.templates.wrappers;

import adnotatio.renderer.templates.FieldPanel;

import com.google.gwt.user.client.ui.Button;
import com.google.gwt.user.client.ui.Widget;
import com.google.gwt.xml.client.Element;

/**
 * A GWT button widget used to clear the form. This button automatically
 * registers a click listener calling the {@link FieldPanel#clear()} or
 * {@link FieldPanel#clear(String,boolean)} methods (it depends on the "for"
 * parameter of the tag defining this widget). <br />
 * Parameters of the tag defining this field:
 * <dl>
 * <dt>"for" (optional)</dt>
 * <dd>This parameter defines the name of the field to clear. If this field is
 * defined then this button cleans up only the specified field. Otherwise it
 * cleans up the whole parent field panel.</dd>
 * <dt>"children" (optional)</dt>
 * <dd>If this parameter is <code>true</code> then the button cleans up all
 * children of the widget with the name defined in the "for" parameter. This
 * parameter is taken into account only if the "for" parameter is defined. The
 * default value of this parameter is <code>true</code>.</dd>
 * </dl>
 * 
 * @see Button
 * @author kotelnikov
 */
public class ClearButtonInfo extends ButtonInfo {

    /**
     * This constructor initializes internal fields of this widget wrapper.
     * 
     * @param panel the form panel owning this widget wrapper
     * @param e the XML element defining this widget wrapper
     */
    public ClearButtonInfo(FieldPanel panel, Element e) {
        super(panel, e);
    }

    /**
     * @see com.google.gwt.user.client.ui.ClickListener#onClick(com.google.gwt.user.client.ui.Widget)
     */
    public void onClick(Widget sender) {
        String name = getAttribute(NS_TEMPLATES + "for");
        if (name != null) {
            boolean children = getAttributeAsBoolean(
                NS_TEMPLATES + "children",
                true);
            fFieldPanel.clear(name, children);
        } else {
            fFieldPanel.clear();
        }
    }
}